extends CharacterBody2D

var move_speed = 200.0
@export var move_target_pos = Vector2(60.0, 180.0)

@onready var navigation_agent_2d = $NavigationAgent2D


# Called when the node enters the scene tree for the first time.
func _ready():
	navigation_agent_2d.path_desired_distance = 4.0
	navigation_agent_2d.target_desired_distance = 4.0
	call_deferred("actor_setup")

func actor_setup():
	await get_tree().physics_frame
	set_move_target(move_target_pos)

func set_move_target(move_target: Vector2):
	navigation_agent_2d.target_position = move_target
	
func _physics_process(delta):
	if navigation_agent_2d.is_navigation_finished():
		return
	var cur_agent_pos = global_position
	var next_path_pos = navigation_agent_2d.get_next_path_position()
	velocity = cur_agent_pos.direction_to(next_path_pos) * move_speed
	move_and_slide()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
